package com.salinity.kun.task;

import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import com.salinity.kun.helper.HarmonicHelper;
import com.salinity.kun.helper.MatrixHelper;

import Jama.Matrix;

/**
 * 计算S0随流量的变化关系
 * 
 * @author Administrator
 *
 */

public class S0Task implements ITask {

	public List<double[][]> getMatrix(double[] q, double[] s0) {

		double[][] a, fb;
		a = new double[3][3];
		fb = new double[3][1];
		int len = q.length;

		for (int i = 0; i < len; i++) {
			a[0][0] += 1;

			a[0][1] += q[i];

			a[0][2] += -s0[i] * q[i];

			a[1][0] += q[i];

			a[1][1] += q[i] * q[i];

			a[1][2] += -s0[i] * q[i] * q[i];

			a[2][0] += s0[i] * q[i];

			a[2][1] += s0[i] * q[i] * q[i];

			a[2][2] += -s0[i] * s0[i] * q[i] * q[i];

			fb[0][0] += s0[i];
			fb[1][0] += s0[i] * q[i];
			fb[2][0] += s0[i] * s0[i] * q[i];
		}

		List<double[][]> rslt = new ArrayList<>();
		rslt.add(a);
		rslt.add(fb);

		return rslt;
	}

	@Override
	public boolean run() throws IOException, ParseException {

		double[] dtQArr = { 13200, 16400, 16600, 31700, 35100, 57900, 64400, 69500 };
		double[] bmS0Arr = { 1.9653, 2.1962, 2.1074, 2.5086, 2.6098, 2.5247, 2.5105, 2.604 };

		List<double[][]> m = getMatrix(dtQArr, bmS0Arr);

		MatrixHelper.printMatrix(m.get(0));
		MatrixHelper.printMatrix(m.get(1));
		HarmonicHelper hh = new HarmonicHelper();
		Matrix rslt = hh.getMatrixRslt(m.get(0), m.get(1), 0);
	
		double[] params = rslt.transpose().getArray()[0];
		
		for (int i = 0; i < dtQArr.length; i++) {
		
			System.out.println((params[0]+params[1]*dtQArr[i])/(1.0+params[2]*dtQArr[i]));
	
		}

		rslt.print(4, 8);
		return false;
	}

	public static void main(String[] args) throws IOException, ParseException {

		ITask task = new S0Task();
		task.run();

	}

}
